/*
 * 修改模型信息
 * @Author: ljb
 * @Date: 2018-03-27 17:53:27 
 * @Last Modified by: ljb
 * @Last Modified time: 2018-04-02 11:04:29
 */
<style lang="less" rel="stylesheet/less" type="text/less" scoped>

    .ivu-form-item-content {
        img {
            width: 150px;
        }
    }

</style>
<template>
<div class="v-admin-Product-edit">
    <Form ref="formValidate" :model="formValidate" :label-width="80">

        <Form-item label="模型名称" prop="name">
            <Input type="text" v-model="formValidate.name" placeholder="请输入模型名称"></Input>
        </Form-item>

        <Form-item label="所属类别" prop="category_id">
            <Select v-model="formValidate.category_id" clearable filterable transfer>
                <Option v-for="model in categories" :value="model.id + ''" :key="model.id">{{ model.name }}</Option>
            </Select>
        </Form-item>

        <Form-item>
            <Button type="primary" @click="updateModel">更新</Button>
        </Form-item>

    </Form>
</div>
</template>

<script>

import API_LIST from 'src/API_LIST';

export default {
    name: 'model-edit',
    props: ['modelDetail','categories'],
    data() {	
        return {

            formValidate : {

                name : '',

                category_id : '',

            }                  //更新模型时的表单

        }
    },
    watch: {
        'modelDetail' : function(){

            if( this.modelDetail ) {

                this.formValidate.name = this.modelDetail.name;
                this.formValidate.category_id = String(this.modelDetail.category_id);

            }

        }
    },
    methods: {

        /**
         * 更新产品类别信息
         * @return {undefined}
         */
        updateModel(){

            const param = {

                _method : 'PUT',

                name : this.formValidate.name,

                category_id : this.formValidate.category_id

            }

            this.$emit('update',this.modelDetail.id,param);

        }

    }
}
</script>